package mop.exception;

/**
 * Exception class for incorrect values
 * 
 * @author	 MOP Team 7
 */
public class IllegalValueException extends Throwable 
{
	
	/**
	 * Initializes an IllegalFieldException with the passed value
	 * 
	 * @param value		The value thats incorrect
	 * @param reason 	The reason why the value is incorrect
	 * 
	 * @post	Set the value
	 */
	public IllegalValueException(String value,String reason)
	{
		this.value = value;
		this.reason = reason;
	}
	
	/**
	 * Return a error message that can be used by the gui
	 * @return An error message describing the incorrect value
	 */
	public String toString()
	{
		
		StringBuffer sb = new StringBuffer();
		sb.append("The following value is not a valid one ! ");
		
		if(this.value == null)
			sb.append("NULL");
		else if(this.value.trim().equals(""))
		{
			sb.append("/emptyString");
		}
		else
		{
			sb.append(this.value);
		}
		
		sb.append("\n due to :\n"+this.reason);
		
		return sb.toString();
		
	}
	
	/**
	 * Weird java demand
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * The value thats causing the problem
	 */
	private final String value;
	
	/**
	 * The reason why its causing the problem
	 */
	private final String reason;
}
